<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>stm32f4_blink_led: D:/123/stm32f4_blink_led-1.2.2-120323/main.c File Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">stm32f4_blink_led
   &#160;<span id="projectnumber">1.2.2-120323</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">D:/123/stm32f4_blink_led-1.2.2-120323/main.c File Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>Sample STM32F4 project.  
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;stdint.h&gt;</code><br/>
<code>#include &quot;<a class="el" href="stm32f4xx_8h_source.html">inc/stm32f4xx.h</a>&quot;</code><br/>
<code>#include &quot;<a class="el" href="config_8h_source.html">config.h</a>&quot;</code><br/>
<code>#include &quot;<a class="el" href="hdr__rcc_8h_source.html">hdr/hdr_rcc.h</a>&quot;</code><br/>
<code>#include &quot;<a class="el" href="hdr__gpio_8h_source.html">hdr/hdr_gpio.h</a>&quot;</code><br/>
<code>#include &quot;<a class="el" href="gpio_8h_source.html">gpio.h</a>&quot;</code><br/>
</div><div class="textblock"><div class="dynheader">
Include dependency graph for main.c:</div>
<div class="dyncontent">
<div class="center"><img src="main_8c__incl.png" border="0" usemap="#_d_1_2123_2stm32f4__blink__led-1_82_82-120323_2main_8c" alt=""/></div>
<map name="_d_1_2123_2stm32f4__blink__led-1_82_82-120323_2main_8c" id="_d_1_2123_2stm32f4__blink__led-1_82_82-120323_2main_8c">
<area shape="rect" id="node5" href="stm32f4xx_8h.html" title="CMSIS Cortex&#45;M4 Device Peripheral Access Layer Header File. This file contains all the peripheral reg..." alt="" coords="87,155,209,181"/><area shape="rect" id="node19" href="config_8h.html" title="Basic configuration of the project." alt="" coords="321,80,393,107"/><area shape="rect" id="node23" href="hdr__rcc_8h.html" title="Header with definition of bits in RCC control registers." alt="" coords="417,80,524,107"/><area shape="rect" id="node26" href="hdr__gpio_8h.html" title="Header with values of bitfields in GPIO control registers." alt="" coords="233,155,348,181"/><area shape="rect" id="node28" href="gpio_8h.html" title="Header for gpio.c." alt="" coords="185,80,247,107"/><area shape="rect" id="node7" href="core__cm4_8h.html" title="CMSIS Cortex&#45;M4 Core Peripheral Access Layer Header File." alt="" coords="119,229,216,256"/><area shape="rect" id="node16" href="system__stm32f4xx_8h.html" title="CMSIS Cortex&#45;M4 Device System Source File for STM32F4xx devices." alt="" coords="241,229,396,256"/><area shape="rect" id="node10" href="core__cm_instr_8h.html" title="CMSIS Cortex&#45;M Core Instruction Access Header File." alt="" coords="100,304,217,331"/><area shape="rect" id="node12" href="core__cm_func_8h.html" title="CMSIS Cortex&#45;M Core Function Access Header File." alt="" coords="242,304,360,331"/><area shape="rect" id="node14" href="core__cm4__simd_8h.html" title="CMSIS Cortex&#45;M4 SIMD Header File." alt="" coords="385,304,519,331"/><area shape="rect" id="node21" href="hdr__bitband_8h.html" title="Header for bit&#45;banding." alt="" coords="387,155,521,181"/></map>
</div>
</div><table class="memberdecls">
<tr><td colspan="2"><h2><a name="func-members"></a>
Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="main_8c.html#a754cfe5d14ab18f45e249298d7e461f3">flash_latency</a> (uint32_t frequency)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Configures Flash latency.  <a href="#a754cfe5d14ab18f45e249298d7e461f3"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="main_8c.html#a1bad51c06000c72357100e09739177e1">fpu_enable</a> (void)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Enables FPU.  <a href="#a1bad51c06000c72357100e09739177e1"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">static uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="main_8c.html#a6e9477b2415b1e0580ebfc034af21105">pll_start</a> (uint32_t crystal, uint32_t frequency)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Starts the PLL.  <a href="#a6e9477b2415b1e0580ebfc034af21105"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="main_8c.html#a59ae3966a97431553c8ed0411bdd7937">system_init</a> (void)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Initializes system.  <a href="#a59ae3966a97431553c8ed0411bdd7937"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="main_8c.html#a840291bc02cba5474a4cb46a9b9566fe">main</a> (void)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">main code block  <a href="#a840291bc02cba5474a4cb46a9b9566fe"></a><br/></td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>This file holds a very basic code for STM32F407VG. This code enables the FPU, all GPIO ports, configures Flash wait-states and enables the PLL to achieve the highest allowed frequency for STM32F407VG (168MHz). Main code block just blinks the LED. The LED port and pin are defined in <a class="el" href="config_8h.html" title="Basic configuration of the project.">config.h</a> file. Target core frequency and quartz crystal resonator frequency are defined there as well.</p>
<dl class="author"><dt><b>Author:</b></dt><dd>Freddie Chopin, <a href="http://www.freddiechopin.info/">http://www.freddiechopin.info/</a> </dd></dl>
<dl class="date"><dt><b>Date:</b></dt><dd>2012-03-23 </dd></dl>
</div><hr/><h2>Function Documentation</h2>
<a class="anchor" id="a754cfe5d14ab18f45e249298d7e461f3"></a><!-- doxytag: member="main.c::flash_latency" ref="a754cfe5d14ab18f45e249298d7e461f3" args="(uint32_t frequency)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">static void <a class="el" href="main_8c.html#a754cfe5d14ab18f45e249298d7e461f3">flash_latency</a> </td>
          <td>(</td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>frequency</em></td><td>)</td>
          <td><code> [static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Configures Flash latency (wait-states) which allows the chip to run at higher speeds. The constants used for calculations are valid when chip's voltage is in 2.7V to 3.6V range.</p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">frequency</td><td>defines the target frequency of the core </td></tr>
  </table>
  </dd>
</dl>

<p><div class="dynheader">
Here is the caller graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="main_8c_a754cfe5d14ab18f45e249298d7e461f3_icgraph.png" border="0" usemap="#main_8c_a754cfe5d14ab18f45e249298d7e461f3_icgraph" alt=""/></div>
<map name="main_8c_a754cfe5d14ab18f45e249298d7e461f3_icgraph" id="main_8c_a754cfe5d14ab18f45e249298d7e461f3_icgraph">
<area shape="rect" id="node3" href="main_8c.html#a6e9477b2415b1e0580ebfc034af21105" title="Starts the PLL." alt="" coords="161,5,234,32"/><area shape="rect" id="node5" href="main_8c.html#a840291bc02cba5474a4cb46a9b9566fe" title="main code block" alt="" coords="283,5,338,32"/></map>
</div>
</p>

</div>
</div>
<a class="anchor" id="a1bad51c06000c72357100e09739177e1"></a><!-- doxytag: member="main.c::fpu_enable" ref="a1bad51c06000c72357100e09739177e1" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">static void <a class="el" href="main_8c.html#a1bad51c06000c72357100e09739177e1">fpu_enable</a> </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td><code> [static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Enables FPU in Cortex-M4 for both privileged and user mode. This is done by enabling CP10 and CP11 coprocessors in CPACR register (possible only when in privileged mode). </p>

<p><div class="dynheader">
Here is the caller graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="main_8c_a1bad51c06000c72357100e09739177e1_icgraph.png" border="0" usemap="#main_8c_a1bad51c06000c72357100e09739177e1_icgraph" alt=""/></div>
<map name="main_8c_a1bad51c06000c72357100e09739177e1_icgraph" id="main_8c_a1bad51c06000c72357100e09739177e1_icgraph">
<area shape="rect" id="node3" href="main_8c.html#a840291bc02cba5474a4cb46a9b9566fe" title="main code block" alt="" coords="147,5,202,32"/></map>
</div>
</p>

</div>
</div>
<a class="anchor" id="a840291bc02cba5474a4cb46a9b9566fe"></a><!-- doxytag: member="main.c::main" ref="a840291bc02cba5474a4cb46a9b9566fe" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int <a class="el" href="main_8c.html#a840291bc02cba5474a4cb46a9b9566fe">main</a> </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Call some static initialization functions and blink the led with frequency defined via count_max variable. </p>

<p><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="main_8c_a840291bc02cba5474a4cb46a9b9566fe_cgraph.png" border="0" usemap="#main_8c_a840291bc02cba5474a4cb46a9b9566fe_cgraph" alt=""/></div>
<map name="main_8c_a840291bc02cba5474a4cb46a9b9566fe_cgraph" id="main_8c_a840291bc02cba5474a4cb46a9b9566fe_cgraph">
<area shape="rect" id="node3" href="main_8c.html#a1bad51c06000c72357100e09739177e1" title="Enables FPU." alt="" coords="114,5,206,32"/><area shape="rect" id="node5" href="main_8c.html#a59ae3966a97431553c8ed0411bdd7937" title="Initializes system." alt="" coords="113,56,207,83"/><area shape="rect" id="node9" href="main_8c.html#a6e9477b2415b1e0580ebfc034af21105" title="Starts the PLL." alt="" coords="123,107,197,133"/><area shape="rect" id="node13" href="gpio_8c.html#ab288132781af1b76dbcd1ef7b039890a" title="Configures pin." alt="" coords="109,157,211,184"/><area shape="rect" id="node7" href="gpio_8c.html#afdbe206b3c49f019757ab09b3cf52b9c" title="GPIO initialization." alt="" coords="275,56,349,83"/><area shape="rect" id="node11" href="main_8c.html#a754cfe5d14ab18f45e249298d7e461f3" title="Configures Flash latency." alt="" coords="259,107,365,133"/></map>
</div>
</p>

</div>
</div>
<a class="anchor" id="a6e9477b2415b1e0580ebfc034af21105"></a><!-- doxytag: member="main.c::pll_start" ref="a6e9477b2415b1e0580ebfc034af21105" args="(uint32_t crystal, uint32_t frequency)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">static uint32_t <a class="el" href="main_8c.html#a6e9477b2415b1e0580ebfc034af21105">pll_start</a> </td>
          <td>(</td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>crystal</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>frequency</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td><code> [static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Configure and enable PLL to achieve some frequency with some crystal. Before the speed change Flash latency is configured via <a class="el" href="main_8c.html#a754cfe5d14ab18f45e249298d7e461f3" title="Configures Flash latency.">flash_latency()</a>. PLL parameters are based on both function parameters. The PLL is set up, started and connected. AHB clock ratio is set to 1:1 with core clock, APB1 - 1:4 (max 42MHz), APB2 - 1:2 (max 84MHz). USB OTG, RNG and SDIO clock is set to (VCO output / 9) (max 48MHz).</p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">crystal</td><td>is the frequency of the crystal resonator connected to the STM32F407VG </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">frequency</td><td>is the desired target frequency after enabling the PLL</td></tr>
  </table>
  </dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>real frequency that was set </dd></dl>

<p><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="main_8c_a6e9477b2415b1e0580ebfc034af21105_cgraph.png" border="0" usemap="#main_8c_a6e9477b2415b1e0580ebfc034af21105_cgraph" alt=""/></div>
<map name="main_8c_a6e9477b2415b1e0580ebfc034af21105_cgraph" id="main_8c_a6e9477b2415b1e0580ebfc034af21105_cgraph">
<area shape="rect" id="node3" href="main_8c.html#a754cfe5d14ab18f45e249298d7e461f3" title="Configures Flash latency." alt="" coords="129,5,234,32"/></map>
</div>
</p>

<p><div class="dynheader">
Here is the caller graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="main_8c_a6e9477b2415b1e0580ebfc034af21105_icgraph.png" border="0" usemap="#main_8c_a6e9477b2415b1e0580ebfc034af21105_icgraph" alt=""/></div>
<map name="main_8c_a6e9477b2415b1e0580ebfc034af21105_icgraph" id="main_8c_a6e9477b2415b1e0580ebfc034af21105_icgraph">
<area shape="rect" id="node3" href="main_8c.html#a840291bc02cba5474a4cb46a9b9566fe" title="main code block" alt="" coords="129,5,183,32"/></map>
</div>
</p>

</div>
</div>
<a class="anchor" id="a59ae3966a97431553c8ed0411bdd7937"></a><!-- doxytag: member="main.c::system_init" ref="a59ae3966a97431553c8ed0411bdd7937" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">static void <a class="el" href="main_8c.html#a59ae3966a97431553c8ed0411bdd7937">system_init</a> </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td><code> [static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Enables all GPIO ports </p>

<p><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="main_8c_a59ae3966a97431553c8ed0411bdd7937_cgraph.png" border="0" usemap="#main_8c_a59ae3966a97431553c8ed0411bdd7937_cgraph" alt=""/></div>
<map name="main_8c_a59ae3966a97431553c8ed0411bdd7937_cgraph" id="main_8c_a59ae3966a97431553c8ed0411bdd7937_cgraph">
<area shape="rect" id="node3" href="gpio_8c.html#afdbe206b3c49f019757ab09b3cf52b9c" title="GPIO initialization." alt="" coords="149,5,224,32"/></map>
</div>
</p>

<p><div class="dynheader">
Here is the caller graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="main_8c_a59ae3966a97431553c8ed0411bdd7937_icgraph.png" border="0" usemap="#main_8c_a59ae3966a97431553c8ed0411bdd7937_icgraph" alt=""/></div>
<map name="main_8c_a59ae3966a97431553c8ed0411bdd7937_icgraph" id="main_8c_a59ae3966a97431553c8ed0411bdd7937_icgraph">
<area shape="rect" id="node3" href="main_8c.html#a840291bc02cba5474a4cb46a9b9566fe" title="main code block" alt="" coords="150,5,205,32"/></map>
</div>
</p>

</div>
</div>
</div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated on Fri Mar 23 2012 00:11:22 for stm32f4_blink_led by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
